﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace ControleRepresentanteSync.View
{
    internal class VisibilityConverter : DependencyObject, IValueConverter
    {
        public static readonly DependencyProperty IsInverseProperty = 
            DependencyProperty.Register("IsInverse", typeof (bool), typeof (VisibilityConverter));

        public bool IsInverse
        {
            get { return (bool) GetValue(IsInverseProperty); }
            set { SetValue(IsInverseProperty, value); }
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool? boolValue = value as bool?;
            bool isTrue = boolValue == true;
            
            if (IsInverse)
            {
                isTrue = !isTrue;
            }
            
            return isTrue ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
